import akshare as ak
import pandas as pd

# 获取指数近一年的数据
start_date = "20140101"
end_date = "20250430"

# 中证全A
index_daily_df_1 = ak.stock_zh_index_daily_em(symbol="sh000985", start_date=start_date, end_date=end_date)

# 沪深300
index_daily_df_2 = ak.stock_zh_index_daily_em(symbol="sh000300", start_date=start_date, end_date=end_date)

# 上证指数
index_daily_df_3 = ak.stock_zh_index_daily_em(symbol="sh000001", start_date=start_date, end_date=end_date)

# 纳斯达克指数
index_daily_df_4 = ak.index_us_stock_sina(symbol=".IXIC")

# 将数据导出到Excel文件
excel_path_1 = "中证全A近十年数据.xlsx"
index_daily_df_1.to_excel(excel_path_1, index=False)

excel_path_2 = "沪深300近十年数据.xlsx"
index_daily_df_2.to_excel(excel_path_2, index=False)

excel_path_3 = "上证指数近十年数据.xlsx"
index_daily_df_3.to_excel(excel_path_3, index=False)

excel_path_4 = "纳斯达克近十年数据.xlsx"
index_daily_df_4.to_excel(excel_path_4, index=False)

print(f"数据已导出完毕！")